/**
 * 
 */
package com.runningfox.humor;

import java.util.Vector;

/**
 * @author luhaiyang
 * 线程引擎
 */
public 	class ProcessPool extends Thread {
	boolean exit = false;
	int clip = 50;
	int max =2;
	Vector<AbstractProcess> tasks = new Vector<AbstractProcess>(max);

	public void run() {
		while (!exit) {
			if (tasks.size() > 0) {
				AbstractProcess p = tasks.remove(0);
				p.run();
			}
		}
	}

	public void execute(AbstractProcess p) {
		if(tasks.size()<max){
			tasks.add(p);
		}
	}

	public void ForceSleep(int time) {
		if (!exit) {
			try {
				sleep(time);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
